<?php
  require_once '../../Helpers/DbHelper.php';
  require_once '../../Controllers/AdminController.php';
  require_once '../../Controllers/SchoolController.php';
  require_once '../../Controllers/UserController.php';
  require_once '../../Helpers/PathHelper.php';

  $u = new UserController();
  $u->evaluatePagePermission(UserController::ADMINISTRATOR);
  //show default list of payment logs, if any
  $a = new AdminController();
  $id = $_GET['pid'];
  $paymentLogs = mysql_fetch_assoc($a->getPaymentLogsById($id));
  //

  if(isset($_POST) && !empty($_POST))
  {
    $status = $a->updatePaymentLogs($id);
    $paymentLogs = mysql_fetch_assoc($a->getPaymentLogsById($id));
  }
  //
  $studentId = $paymentLogs['StudentId'];
  $amount = $paymentLogs['PaymentAmount'];
  $receipt = $paymentLogs['ReceiptNumber'];
  $date = $paymentLogs['PaymentDate'];

?>
<html>
  <head>
    <title>School Enrollment :: Payments</title>
    <?php
      require_once '../commons.php';
      renderHeaderStyles() ;
    ?>
    <link href="../../assets/jquery_ui.css" rel="stylesheet" type="text/css" />
    <link href="../../assets/theme.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../assets/js/jquery-1.6.2.min.js"></script>
     <script type="text/javascript" src="../../assets/js/jquery-ui-1.8.16.custom.min.js"></script>
     <script type="text/javascript" src="../../assets/js/jquery.ui.tabs.js"></script>
    <script type="text/javascript">
      $(document).ready(function()
      {
        $("#datepicker").datepicker({dateFormat:'yy-mm-dd'});
      }

      );
    </script>
  </head>
  <body>
  <div class="admin-container">
    <?php renderAdminNav(); ?>
  </div>
  <div class="container">
    <h1>Edit Payment Logs</h1>
    <form name="fees-form" method="post">
      <table align="center" class="labels">
        <tr>
          <td><label for="student-id">Student ID:</label></td>
          <td><input type="text" name="student-id" value="<?php echo $studentId?>"/></td>
        </tr>
        <tr>
          <td><label for="payment-amount">Payment Amount:</label></td>
          <td><input type="text" name="payment-amount" value="<?php echo $amount?>" /></td>
        </tr>
        <tr>
          <td><label for="receipt-number">Receipt Number:</label></td>
          <td><input type="text" name="receipt-number" value="<?php echo $receipt?>"/></td>
        </tr>
        <tr>
          <td><label for="payment-date">Payment Date:</label></td>
          <td><input type="text" name="payment-date" id="datepicker" value="<?php echo $date?>"/></td>
        </tr>
        <tr><td><input type="submit" name="save-payment" value="Save" /></td></tr>
      </table>
    </form>
    <div class="notices" style="padding-left: 120px"><?php if($status) echo 'Successfully updated payment logs.'?></div>
    <hr />
    <a href="<?php echo PathHelper::getBaseUrl()?>/Views/Admin/payments.php" id="prev-next">&larr;&nbsp;Back</a>
  </div>
  </body>
</html>